//
//  wordsCollectionViewCell.m
//  OurRelaxDemo
//
//  Created by 于宾尧 on 15/7/3.
//  Copyright (c) 2015年 于宾尧. All rights reserved.
//

#import "wordsCollectionViewCell.h"

@implementation wordsCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self subMyViews];
        
    }
    return self;
}

-(void)subMyViews
{
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(60, 500, 60, 30);
    
    [self.contentView addSubview:button];
    
    if ([[UIScreen mainScreen] bounds].size.width >= 375) {
        
        self.wordImage = [[UIImageView alloc]initWithFrame:CGRectMake(10, 20, self.contentView.frame.size.width - 10, (self.contentView.frame.size.height / 2) - 20)];
        
    } else {
    
        self.wordImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 20, self.contentView.frame.size.width - 10, (self.contentView.frame.size.height / 2) - 40)];
    }
    self.wordImage.layer.masksToBounds = YES;
    self.wordImage.layer.cornerRadius = 20;

    UIColor *bg_color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"headerViewCache.jpeg"]];
    self.wordImage.backgroundColor = bg_color;
    [self.contentView addSubview:self.wordImage];
    
    
    self.wordLabel = [[UILabel alloc]init];
    if ([[UIScreen mainScreen] bounds].size.width >= 375) {
        
        self.wordLabel.frame = CGRectMake(50, 400, 300, 20);
        
    } else {
    
        self.wordLabel.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width - 220, _wordImage.frame.origin.y + _wordImage.frame.size.height + 40, 220, 20);
    }
    self.wordLabel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"shi.png"]];
    [self.wordLabel setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"headerViewCache.jpeg"]]];
    self.wordLabel.backgroundColor = [UIColor cyanColor];
    self.wordLabel.textColor = [UIColor whiteColor];
    self.wordLabel.numberOfLines = 0;
    self.wordLabel.layer.masksToBounds = YES;
    self.wordLabel.layer.cornerRadius = 5;

    
    
    CGRect textFrame = self.wordLabel.frame;
    textFrame.size.height =[self.wordLabel.text boundingRectWithSize:CGSizeMake(textFrame.size.width, CGFLOAT_MAX)
    options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
    attributes:[NSDictionary dictionaryWithObjectsAndKeys:self.wordLabel.font,NSFontAttributeName, nil] context:nil].size.height;
    if ([[UIScreen mainScreen] bounds].size.width >= 375) {
        
        self.wordLabel.frame = CGRectMake(210, 390, 300, textFrame.size.height);
        
    } else {
    
        self.wordLabel.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width - 220, _wordImage.frame.size.height, 220, textFrame.size.height);
        self.wordLabel.font = [UIFont systemFontOfSize:14.0];
    }

    
    
    
    
    [self.contentView addSubview:self.wordLabel];
    
    if ([[UIScreen mainScreen] bounds].size.width >= 375) {
        
        self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(250, (self.contentView.frame.size.height / 2) + 10, 110, 30)];
    } else {
    
        self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width - 110, _wordImage.frame.origin.y + _wordImage.frame.size.height , 110, 30)];
    }
    self.nameLabel.backgroundColor = [UIColor clearColor];
    self.nameLabel.font = [UIFont systemFontOfSize:11.0];
    self.nameLabel.numberOfLines = 0;
    
    [self.contentView addSubview:self.nameLabel];
    
    
//    self.timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 390, 60, 60)];
//    self.timeLabel.backgroundColor = [UIColor yellowColor];
//    [self.contentView addSubview:self.timeLabel];
    
    self.playButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.playButton.backgroundColor = [UIColor clearColor];
    if ([[UIScreen mainScreen] bounds].size.width >= 375) {
        
        self.playButton.frame = CGRectMake((self.contentView.frame.size.width / 2) - 20, self.contentView.frame.size.height - 100, 60, 60);
        
    } else {
    
        self.playButton.frame = CGRectMake((self.contentView.frame.size.width / 2.0) + 20, self.contentView.frame.size.height - 85, 40, 40);
    }
    [self.playButton addTarget:self action:@selector(playAction) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.playButton];
    
    UIButton *nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
    nextButton.backgroundColor = [UIColor clearColor];
    if ([[UIScreen mainScreen] bounds].size.width >= 375) {
        
        nextButton.frame = CGRectMake((self.contentView.frame.size.width / 2) + 90, self.contentView.frame.size.height - 80, 40, 40);
        
    } else {
    
        nextButton.frame = CGRectMake((self.contentView.frame.size.width / 2.0) + 80, self.contentView.frame.size.height - 80, 30, 30);
    }
    [nextButton addTarget:self action:@selector(nextAction) forControlEvents:UIControlEventTouchUpInside];
    [nextButton setBackgroundImage:[UIImage imageNamed:@"down.png"] forState:UIControlStateNormal];
    [self.contentView addSubview:nextButton];
    
    self.catImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mao.png"]];
    self.catImage.frame = CGRectMake(0, self.contentView.frame.size.height - 160, 140, 140) ;
//    self.catImage.backgroundColor = [UIColor blackColor];
    [self.contentView addSubview:self.catImage];
    
    self.bubleImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"hudie1.jpg"]];
    self.bubleImage.frame = CGRectMake(40, self.contentView.frame.size.height - 200, 50, 50);
//    self.bubleImage.layer.masksToBounds = YES;
//    self.bubleImage.layer.cornerRadius = 180;
    [self.contentView addSubview:self.bubleImage];
    
    self.bubleImage2 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"hudie2"]];
    if ([[UIScreen mainScreen] bounds].size.width >= 375) {
        
        self.bubleImage2.frame = CGRectMake(10, 340, 70, 120) ;
        
    } else {
    
        self.bubleImage2.frame = CGRectMake(_wordImage.frame.origin.x + 35, _wordImage.frame.origin.y + _wordImage.frame.size.height - 40, 80, 130);
    }
    [self.contentView addSubview:self.bubleImage2];
                        
}




-(void)setWordMdl:(wordModel *)wordMdl
{
    if (_wordMdl != wordMdl) {
        [_wordMdl release];
        _wordMdl = [wordMdl retain];
    }
    NSURL *url = [NSURL URLWithString:wordMdl.strThumbnailUrl];
    [self.wordImage sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"headerViewCache.jpeg"]];
    
    self.nameLabel.text = wordMdl.strAuthor;
    self.wordLabel.text = wordMdl.strContent;
    CGRect textFrame = self.wordLabel.frame;
    textFrame.size.height =[self.wordLabel.text boundingRectWithSize:CGSizeMake(textFrame.size.width, CGFLOAT_MAX)options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
                                                          attributes:[NSDictionary dictionaryWithObjectsAndKeys:self.wordLabel.font,NSFontAttributeName, nil] context:nil].size.height;
    if ([[UIScreen mainScreen] bounds].size.width >= 375) {
        
        self.wordLabel.frame = CGRectMake(100, 420, 260, textFrame.size.height);
        
    } else {
    
        self.wordLabel.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width - 220, _nameLabel.frame.origin.y + _nameLabel.frame.size.height + 5, 220, textFrame.size.height);
    }

    
    [self.wordLabel setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"word.jpg"]]];
    
    
    [self.contentView addSubview:self.wordLabel];

    
    
    if ([Player shareDataHandle].player.state == STKAudioPlayerStatePlaying) {
        [self.playButton setBackgroundImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
    }else
    {
        [self.playButton setBackgroundImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
    }
    
}



-(void)nextAction
{
    [Player nextPlayRadio];
    
}

-(void)playAction
{
    if ([Player shareDataHandle].player.state == STKAudioPlayerStatePlaying ) {
        [[Player shareDataHandle].player pause];
        [self.playButton setBackgroundImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
    }else{
        [[Player shareDataHandle].player resume];
        [self.playButton setBackgroundImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
        
    }
}




@end
